# agent_interface.py
from datetime import datetime

from intent_agent import IntentRecognizer
from scenario_knowledge import get_scenario_definitions


class IntentAgent:
    def __init__(self):
        self.recognizer = IntentRecognizer()
        self.scenario_definitions = get_scenario_definitions()

    def process_input(self, user_input: str) -> dict:
        """
        处理用户输入并返回结构化响应

        参数:
            user_input: 用户输入的自然语言文本

        返回:
            dict: 包含识别结果和元数据的响应
        """
        if not user_input.strip():
            return {
                "status": "error",
                "message": "输入不能为空"
            }

        explanation = self.recognizer.explain_decision(user_input)

        return {
            "status": "success",
            "input": user_input,
            "scenario": {
                "id": explanation["recognized_scenario"],
                "name": explanation["scenario_name"],
                "confidence": explanation["confidence"]
            },
            "explanation": {
                "matched_keywords": explanation["matched_keywords"],
                "similar_examples": explanation["similar_examples"]
            },
            "available_scenarios": self.scenario_definitions,
            "timestamp": datetime.now().isoformat()
        }

    def get_scenario_definitions(self) -> dict:
        """获取所有场景的定义"""
        return self.scenario_definitions
